package love.yuanmengrobot.als.business.dao.impl;
/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:CHJY创幻
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/6/7 19:11
 */

import love.yuanmengrobot.als.business.dao.FindStudentInfoDao;
import love.yuanmengrobot.als.business.javaBean.Student;
import love.yuanmengrobot.als.business.javaBean.StudentViewCredit;
import love.yuanmengrobot.als.utilPublic.JdbcUtil;
import love.yuanmengrobot.als.utilPublic.SqlString;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class FindStudentInfoDaoImpl implements FindStudentInfoDao {

    @Override
    public StudentViewCredit selectInfo(String id) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        StudentViewCredit svc = null;
        try {
            conn = JdbcUtil.getConnection();
            stmt = conn.createStatement();
            rs = stmt.executeQuery(SqlString.selectStudentNameById(id));
            if (rs != null) {
                if (rs.next()) {
                    svc = new StudentViewCredit();
                    svc.setStudentId(String.valueOf(rs.getInt(1)));
                    svc.setStuNo(rs.getString("STU_NO"));
                    svc.setMajorId(rs.getString("MAJOR_ID"));
                    svc.setStuName(rs.getString("STU_NAME"));
                    svc.setGrade(rs.getString("GRADE"));
                    svc.setClazz(rs.getString("CLAZZ"));
                    return svc;
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {//回收资源
            JdbcUtil.close(rs, stmt, conn);
        }

        return svc;
    }


}
